package array

func productExceptSelf(nums []int) []int {
	right, left, ans := make([]int, len(nums)), make([]int, len(nums)), make([]int, len(nums))

	right[0] = 1

	for i := 1; i < len(nums); i++ {
		right[i] = right[i-1] * nums[i-1]
	}

	left[len(left)-1] = 1
	for i := len(left) - 2; i >= 0; i-- {
		left[i] = left[i+1] * nums[i+1]
	}

	for i := 0; i < len(nums); i++ {
		ans[i] = right[i] * left[i]
	}

	return ans

}
